package com.rayson.oneapi.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Author: rayson
 * Description:
 * Version: 1.0
 * Date: 2024-09-01 21:46
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    private int code;

    private String msg;

    private T data;


    public static <T> R<T> ok(T data) {
        return ok(data, "ok");
    }

    public static <T> R<T> ok(T data, String msg) {
        R<T> r = new R<>();
        r.setCode(CommonConst.SUCCESS_CODE);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> R<T> error(String msg) {
        R<T> r = new R<>();
        r.setCode(CommonConst.SYSTEM_ERROR_CODE);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }
}
